package com.thread.collection;

import java.util.Queue;
import java.util.Vector;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;

public class TicketConcurrentLinkedQueue {

    static Queue<String> tickets = new ConcurrentLinkedQueue<>();
    static{
        for(int i=0;i<1000;i++)tickets.add("ticket"+i);
    }

    public static void main(String[] args) {
        for(int i=0;i<1000;i++){
            new Thread(()->{
                while(true){//虽然这里枷锁了，但是下面线程睡眠，让出cput依然会存在超卖

                    String ticket = tickets.poll();
                    /*String ticket = tickets.peek(); 取出不删除*/
                    if(null == ticket)break;
                    else System.out.println("get "+ticket);
                }
            }).start();
        }
    }

}

